import Vue from 'vue';
import VueRouter from 'vue-router';
import NProgress from 'nprogress';
import routes from './router';
import store from '../store';

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  NProgress.start();
  next();
});

router.afterEach(() => {
  // 项目跳转后取消全局loading
  const { loading } = store.getters;
  loading && store.commit('UPDATE_LOADING');

  NProgress.done();
});

Vue.use(VueRouter);
export default router;
